package org.jshand.jxc.business.book.panel.booklist;

import java.awt.Component;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.JTextField;

import org.jshand.jxc.business.BusinessFrame;
import org.jshand.jxc.business.book.vo.Student;
import org.jshand.jxc.util.SwingUtils;

public class ButtonCellEditor extends DefaultCellEditor {

	 private JPanel panel;

	 private JButton button;

	 private JTable table;
	 
	 int r,c;
	 
	 
	public ButtonCellEditor() {
		super(new JTextField());
		
		this.setClickCountToStart(1);
		
		 this.panel = new JPanel();

        // panel使用绝对定位，这样button就不会充满整个单元格。
        this.panel.setLayout(null);
        
        this.button = new JButton();

        // 设置按钮的大小及位置。
        this.button.setBounds(0, 0, 90, 25);
//        get
        this.button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				StudentTableModel st = (StudentTableModel) table.getModel();
				Student student = st.getstudents().get(r);
				System.out.println(student);
				StudentEditor dialog = new StudentEditor(SwingUtils.getMainFrame(), true);
				dialog.setLocationRelativeTo(null);
				dialog.setVisible(true);
			}
		});
        // 添加按钮。
        this.panel.add(this.button);
        
        
        
        
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		button.setText("修改"+row+"\t"+column+"\r");
//		System.out.println("abccbcbc");
		r = row;
		c = column;
		this.table = table;
		return panel;
	}

	
	
	

}
